home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / ScreenSavers / Clock screen saver Folder / trackidle.c < prev   
Encoding:
C/C++ Source or Header  |  1993-03-01  |  1.3 KB  |  54 lines  |  [TEXT/MPS ]

  1. #include "screen.h"
  2.  
  3. long IDLETICKS = (60*60*5);
  4.  
  5. static Boolean    forcedIdle = FALSE;
  6. static Point     mouseNow,
  7.                 mouseLast = { 0, 0};
  8. static KeyMap    keysNow,
  9.                 keysLast = { 0, 0, 0, 0};
  10.  
  11. /*
  12. Returns TRUE if screen has been idle more than IDLETICKS ticks, else FALSE
  13. */
  14. Boolean idle(struct screen *screen) {
  15.  
  16.     GetMouse(&mouseNow);
  17.     LocalToGlobal(&mouseNow);
  18.     if (PtInRect(mouseNow,&screen->globalRect)) {
  19.         if ( (abs(mouseNow.h-mouseLast.h)>4) || (abs(mouseNow.v-mouseNow.v)>4) ) {
  20.             screen->idleSince = TickCount();
  21.             mouseLast = mouseNow;
  22.             } // mouse moved
  23.         GetKeys(keysNow);
  24.         if (    keysNow[0]!=keysLast[0] ||
  25.                 keysNow[1]!=keysLast[1] ||
  26.                 keysNow[2]!=keysLast[2] ||
  27.                 keysNow[3]!=keysLast[3]    ) {
  28.             keysLast[0]=keysNow[0];
  29.             keysLast[1]=keysNow[1];
  30.             keysLast[2]=keysNow[2];
  31.             keysLast[3]=keysNow[3];
  32.             screen->idleSince = TickCount();
  33.             } // key pressed
  34.         } // if mouse on screen    
  35.  
  36.     if (screen->idleSince + IDLETICKS < TickCount())
  37.         return TRUE;
  38.     return FALSE;
  39. }
  40.  
  41. /*
  42. Simulate the condition of the machine being idle.  This forces the saver on.
  43. */
  44. void simulateidle(struct screen *screen) {
  45.  
  46.     screen->idleSince = TickCount() - (IDLETICKS-1);
  47.     GetMouse(&mouseNow);
  48.     LocalToGlobal(&mouseNow);
  49.     if (PtInRect(mouseNow,&screen->globalRect)) {
  50.         mouseLast=mouseNow;
  51.         GetKeys(keysLast);
  52.         }
  53.     return;
  54. }